<template>
  <div style="width:100%;">
      <main-header :logout="logoutHandle" :nowdate="nowdate" :nowuser="userName" :showDropdown="showDropdown"></main-header>  
      <top-menu></top-menu>   
  </div>
</template>

<script>
  import {mapGetters} from "vuex";
  import topMenu from "./topMenu";
  import { clearLoginInfo } from '@/utils';
  import { Date2String, Date2Week, isAuthorizedUrl } from '@/utils/funcs';

  export default {
    name: 'head-nav',
    data() {
      return {
        menu: {
          userBgcolor: '#f0f2f5'
        },
        nowdate: '',
        userName: this.$store.state.user.name,
        showDropdown: false
      }
    },
    components: {
      topMenu
    },
    computed: {
      ...mapGetters(['name', 'avatar', 'sidebar']),
      headNavWidth() {
        // return document.body.clientWidth - this.sidebar.width
      }

    },
    created() {
      let date = new Date();
      this.nowdate = Date2String(date,'yyyy-MM-dd')+' '+Date2Week(date);
    },
    mounted() {
    },
    methods: {
      logoutHandle() {
          this.$confirm(`确定进行[退出]操作?`, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
          }).then(() => {
              this.$http({
                  url: this.$http.adornUrl('/sys/logout'),
                  method: 'post',
                  data: this.$http.adornData()
              }).then(({data}) => {
                  if (data && data.code === 0) {
                      clearLoginInfo()
                      localStorage.clear();
                      sessionStorage.clear()
                      this.$store.commit("updatechecktask", {});
                      this.$store.commit("checkChanel", {});
                      // console.log(this.$store.state, 'this.$store.state');
                      this.$router.push({name: 'login'})
                  }
              })
          }).catch(() => {
          })
      },
    }
  }
</script>

<style scoped lang='less'>
  .right-nav {
    display: flex;
    flex: 1;
    width: calc(100% - 180px);
    // padding-right: 15px;
    justify-content: space-between;
    box-shadow: 0px 2px 5px 0px rgba(237, 233, 233, 0.5);
    background: #eeeeee;
    border-bottom: 1px solid #dbdbdb;
  }

  .head-nav {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    z-index: 29;
    transition: width .2s;
    justify-content: space-between;
    height: 80px;
    box-sizing: border-box;
    background: #fff;

    .logout {
      vertical-align: middle;
      cursor: pointer;
    }
  }

  .middle {
    align-items: center;
    border: 1px solid;
  }

  .userinfo-right {
    width: 100px;
    padding: 0 10px;
    box-sizing: border-box;
    text-align: center;
    cursor: pointer;

    .i_icon {
      // font-size: 28px;
      font-size: 26px; //2020-03-17
      color: #a5a5a5;
      margin-top: 15px;
    }

    .tip {
      color: #666;
      font-size: 14px;
      margin-top: 3px;
    }
  }

  .userinfo {
    line-height: 60px;
    text-align: right;
  }

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    vertical-align: middle;
    display: inline-block;
  }

  .langAvatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    vertical-align: middle;
    display: inline-block;
  }

  .welcome {
    display: inline-block;
    vertical-align: middle;
    padding: 0 5px;

    .name {
      line-height: 20px;
      text-align: center;
      font-size: 12px;
    }

    .avatarname {
      color: #a9d86e;
      font-weight: bolder;
      font-size: 13px;
    }
  }

  .username {
    cursor: pointer;
    margin-right: 5px;
  }

  .border {
    border: 1px solid;
  }

  .notify-row {
    line-height: 60px;
    flex: 1;

    ul {
      display: flex;
      justify-content: space-around;
    }
  }

  ul.top-menu > li {
    position: relative;
  }

  .user_left_logo {
    width: 252px;
    height: 80px;
    align-items: center;
    justify-content: center;

    img {
      // height: 55px;
    }
  }
</style>
